<template>
  <div class="layout-all">
    <el-row>
      <el-col :xs="24" :sm="12" :lg="12">
        <el-form ref="form" :rules="rules" :model="form" label-width="100px">
          <el-form-item label="名称:" prop="title">
            <el-input v-model="form.title" placeholder="请输入名称" style="width: 70%;"/>
          </el-form-item>

          <el-form-item label="封面:" prop="thumb">
            <upload-pic :thumb="form.thumb" @update:thumb="form.thumb=$event" width="100" :append="true"/>
          </el-form-item>
          <el-form-item label="路径:" prop="url" >
            <el-input v-model="form.url" placeholder="请输入路径" style="width: 70%;" />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-close" circle @click="bk()" />
            <el-button
              type="success"
              icon="el-icon-check"
              circle
              @click="onSubmit('form')"
            />
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :xs="24" :sm="12" :lg="12">
        <div>选择跳转地址</div>  
        <url-address @selectMenu="selectMenu" @selectActivity="selectActivity"></url-address>
      </el-col>
    </el-row>
    
  </div>
</template>

<script>
import urlAddress from '@/components/url_address/urlAddress'

  export default {
    components: { urlAddress},
    props:{
      data:{
        type:Object,
        default:()=>{
          return{
            title:'',
            thumb:'',
            url:'',
            status:1,
          }
          
        }
      }
    },
    name:"Navigation",
    data() {
      return {
        form:{},
        rules: {
          title: [
            { required: true, message: '请输入名称', trigger: 'blur' }
          ],
          thumb: [
            { required: true, message: '请输入封面', trigger: 'blur' }
          ]
        }

      };
    },
    mounted(){
      this.form=this.data
      console.log(this.form)
    },
    methods: {
      selectActivity (url) {
        this.form.url = url
      },
      selectMenu (item) {

          this.form.thumb = this.form.thumb ? this.form.thumb : item.thumb
          this.form.title = this.form.title ? this.form.title : item.title
          this.form.url = item.path
      },
      bk(){
        this.$emit('bk');
      },
      onSubmit(formName) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.$emit('onSubmit',this.form);
          } else {
            console.log('error submit!!')
            return false
          }
        })
        console.log('submit!')
      },
    }
  }
</script>